﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using RStein.Posterous.API;
using System.Web;
using System.IO;

namespace PosterousDemo1
{
    class Program
    {
        public const int WEB_TIMEOUT = 100000;
        static void Main(string[] args)
        {
            PosterousApplication.Current.ApplicationName = "Moje aplikace";
            PosterousApplication.Current.ApplicationUrl = "http://renestein.net";
            IRawRequestResponsePublisher publisher =
                PosterousApplication.Current.GetInterface<IRawRequestResponsePublisher>();
           
            Debug.Assert(publisher != null);
            publisher.WebRequestCreated += ((_, e) => e.Value.Timeout = WEB_TIMEOUT);
          

            IPosterousAccount posterousAccount = PosterousApplication.Current.GetPosterousAccount("rene@renestein.net", "xxx");
            posterousAccount.LoadSites();
            var body = HttpUtility.HtmlDecode(posterousAccount.PrimarySite.Posts.First().Body);
            
            Console.WriteLine(body); 
          
          posterousAccount.SitesLoaded += (o, e) => Console.WriteLine(e.Value.Count());
            posterousAccount.LoadSitesAsync();
            Console.ReadLine();
        }
    }
}
